home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / update.fr_ / update.fr
Text File  |  1995-07-04  |  6KB  |  191 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "UPDATEr"
  5.    ClientHeight    =   3660
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1485
  8.    ClientWidth     =   5520
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   4065
  19.    Left            =   1035
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   3660
  22.    ScaleWidth      =   5520
  23.    Top             =   1140
  24.    Width           =   5640
  25.    Begin VB.CommandButton cmdClose 
  26.       Caption         =   "&Close"
  27.       Height          =   495
  28.       Left            =   3720
  29.       TabIndex        =   3
  30.       Top             =   2520
  31.       Width           =   1215
  32.    End
  33.    Begin VB.CommandButton cmdRestore 
  34.       Caption         =   "&Restore"
  35.       Height          =   495
  36.       Left            =   2100
  37.       TabIndex        =   2
  38.       Top             =   2520
  39.       Width           =   1215
  40.    End
  41.    Begin VB.CommandButton cmdUpdate 
  42.       Caption         =   "&Update"
  43.       Height          =   495
  44.       Left            =   540
  45.       TabIndex        =   1
  46.       Top             =   2520
  47.       Width           =   1215
  48.    End
  49.    Begin VB.ListBox lstData 
  50.       BeginProperty Font 
  51.          name            =   "MS Sans Serif"
  52.          charset         =   0
  53.          weight          =   400
  54.          size            =   8.25
  55.          underline       =   0   'False
  56.          italic          =   0   'False
  57.          strikethrough   =   0   'False
  58.       EndProperty
  59.       Height          =   1590
  60.       Left            =   540
  61.       TabIndex        =   0
  62.       Top             =   480
  63.       Width           =   4395
  64.    End
  65. End
  66. Attribute VB_Name = "Form1"
  67. Attribute VB_Creatable = False
  68. Attribute VB_Exposed = False
  69. Option Explicit
  70.  
  71.  
  72. Private Sub cmdUpdate_Click()
  73.     Dim db As DATABASE
  74.     Dim dbName As String
  75.     Dim sql As String
  76.     
  77.     On Error GoTo UpdateError
  78.  
  79.   ' Get the database name and open the database.
  80.     dbName = BiblioPath()       ' BiblioPath is a function in READINI.BAS
  81.     Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
  82.     
  83.     ' Build the SQL statement, beginning with the UPDATE clause, which
  84.     ' designates the table to be modified.
  85.     sql = "UPDATE Publishers"
  86.     
  87.     ' Set the new values of each field to be modified.
  88.     sql = sql & " SET City = 'Indianapolis', Address = '201 W. 103rd St.',"
  89.     sql = sql & " Zip = '46290'"
  90.     
  91.     ' Designate the records to be modified.
  92.     sql = sql & " WHERE ([City] = 'Carmel')"
  93.     sql = sql & " AND (Address LIKE '*11711*College*')"
  94.     
  95.     ' Execute the update query.
  96.     db.Execute sql
  97.  
  98.     ' Show the modified records in the list box.
  99.     ListRecords "Indianapolis"
  100.     
  101. Exit Sub
  102. UpdateError:
  103.     MsgBox Error$, vbExclamation
  104. Exit Sub
  105.     
  106. End Sub
  107.  
  108. Private Sub cmdRestore_Click()
  109.     Dim db As DATABASE
  110.     Dim dbName As String
  111.     Dim sql As String
  112.  
  113.     On Error GoTo RestoreError
  114.     
  115.     
  116.    ' Get the database name and open the database.
  117.     dbName = BiblioPath()       ' BiblioPath is a function in READINI.BAS
  118.     Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
  119.     ' Build the SQL statement, beginning with the UPDATE clause, which
  120.     ' designates the table to be modified.
  121.     sql = "UPDATE Publishers"
  122.     
  123.     ' Set the new values of each field to be modified.
  124.     sql = sql & " SET City = 'Carmel', Address = '11711 N. College Ave.',"
  125.     sql = sql & " Zip = '46032'"
  126.     
  127.     ' Set the new values of each field to be modified.
  128.     sql = sql & " WHERE ([City] = 'Indianapolis')"
  129.     sql = sql & " AND (Address = '201 W. 103rd St.')"
  130.     
  131.     ' Execute the update query.
  132.     db.Execute sql
  133.  
  134.     ' Execute the update query.
  135.     ListRecords "Carmel"
  136.  
  137. Exit Sub
  138. RestoreError:
  139.     MsgBox Error$, vbExclamation
  140. Exit Sub
  141. End Sub
  142.  
  143. Private Sub ListRecords(cityName As String)
  144.     Dim db As DATABASE
  145.     Dim dbName As String
  146.     Dim rs As Recordset
  147.     Dim sql As String
  148.     Dim streetAddress As String
  149.     
  150.     On Error GoTo ListError
  151.  
  152.     ' Set the correct street address based on the city name.
  153.     If cityName = "Indianapolis" Then
  154.         streetAddress = "201 W. 103rd St."
  155.     Else
  156.         streetAddress = "11711 N. College Ave."
  157.     End If
  158.  
  159.     ' Get the database name and open the database.
  160.     dbName = BiblioPath()       ' BiblioPath is a function in READINI.BAS
  161.     Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
  162.     
  163.     ' Create the recordset for the list box.
  164.     sql = "SELECT [Company Name], [Address], [City], [State], [Zip]"
  165.     sql = sql & " FROM Publishers"
  166.     sql = sql & " WHERE [City] = '" & cityName & "'"
  167.     sql = sql & " AND [Address] = '" & streetAddress & "'"
  168.     Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
  169.     
  170.     lstData.Clear
  171.     
  172.     ' Show each record in the list box.
  173.     If rs.RecordCount > 0 Then
  174.         rs.MoveFirst
  175.         Do
  176.             lstData.AddItem Left$(rs![Company Name], 10) _
  177.                 & ", " & rs![Address] & ", " & rs![City] _
  178.                 & ", " & rs![State] & " " & rs![Zip]
  179.             rs.MoveNext
  180.         Loop While Not rs.EOF
  181.     End If
  182. Exit Sub
  183. ListError:
  184.     MsgBox Error$, vbExclamation
  185. Exit Sub
  186. End Sub
  187.  
  188. Private Sub cmdClose_Click()
  189.     End
  190. End Sub
  191.